<?php
namespace Admin\Controller;
use Think\Controller;
/**
 * 后台登陆控制器
 */
class LoginController extends Controller{
	//后台登陆视图
	public function index(){
		$this->display();
	}
	//登录表单操作
	public function login(){
		if(!IS_POST)	E('页面不存在');

		if(!check_verify(I('verify'))){
			$this->error('验证码错误');
		}
		$db = M('user');
		$user = $db->where(array('username'=>I('uname')))->find();
		if(!$user || $user['password'] != I('pwd','','md5')){
			$this->error('账号或密码错误！');
		}

		$data = array(
			'id'		=>	$user['id'],
			'logintime'	=>	time(),
			'loginip'	=>	get_client_ip()
			);
		$db->save($data);//更新时间和ip

		//存入session
		session('uid',$user['id']);
		session('username',$user['username']);
		session('logintime',date('Y-m-d H:i:s',$user['logintime']));
		session('loginip',$user['loginip']);

		$this->success('登陆成功...',U('Index/index'));

	}
	//验证码
	public function verify(){
		$config = array(
			'length'	=>4,//修改默认长度
			'useCurve'	=>false,//不使用混淆曲线
			);
		$verify = new \Think\Verify($config);
		$verify->entry();
	}
}